// pages/mine/mine.js
import { request } from "../../utils/index.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    items:[
      {
        title:"领取分换好礼",
        icon:"../../images/mine/mine_integral.png"
      },
      {
        title:"我的兑换",
        icon:"../../images/mine/mine_convert.png"
      },
      {
        title:"我的兼职收藏",
        icon:"../../images/mine/mine_collect.png"
      },
      {
        title:"社团合作",
        icon:"../../images/mine/mine_community.png"
      },
      {
        title:"设置",
        icon:"../../images/mine/mine_setting.png"
      },
    ],
    userInfo:{},
    isLogin:true,
  },

   // 查询用户信息
   getUserInfo () {
    request({ url: "/api/auth/me" })
    .then(result => {
      console.log(result)
      this.setData({
        userInfo:result.data
      })
    })
  },

  // 点击菜单栏
  onMenu(event) {

    if (this.data.isLogin == false) {
      return wx.navigateTo({
        url: '/pages/login/login',
      })
    }

    let index = event.currentTarget.dataset.value;
    if (index == "0") {
      wx.navigateTo({
        url: '/pages/myWallet/myWallet',
      })
    }else if (index == "1") {
      wx.navigateTo({
        url: '/pages/myResume/myResume',
      })
    }else {
      // wx.navigateTo({
      //   url: '/pages/deliveryGoods/deliveryGoods',
      // })
    }

  },

  // 点击我的兼职
  onMyTask(event){

    if (this.data.isLogin == false) {
      return wx.navigateTo({
        url: '/pages/login/login',
      })
    }

    let status = event.currentTarget.dataset.value;
    wx.navigateTo({
      url: '/pages/myTask/myTask?status='+ status,
    })
  },

  // 点击底部设置
  onCell(event) {

    if (this.data.isLogin == false) {
      return wx.navigateTo({
        url: '/pages/login/login',
      })
    }

    let index = event.currentTarget.dataset.value;
    if (index == 0) {
      wx.navigateTo({
        url: '/pages/goods/goods',
      })
    }else if (index == 1) {
      wx.navigateTo({
        url: '/pages/myExchange/myExchange',
      })
    }else if (index == 2) {
      wx.navigateTo({
        url: '/pages/collect/collect',
      })
    }else if (index == 3) {
      wx.navigateTo({
        url: '/pages/sponsor/sponsor',
      })
    }else if (index == 4) {
      wx.navigateTo({
        url: '/pages/setting/setting',
      })
    }
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var token = wx.getStorageSync("token");
    if (token) {
      this.setData ({
        isLogin:true
      })
      this.getUserInfo();
    }else {
      this.setData ({
        isLogin:false
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})